package com.java.base.exercise.designmode.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author RenPu
 * @Date 2022/11/12 20:48
 * @Version 1.0
 * @Description: 被观察者实体
 **/
public class WeatherData implements Subject {

    //观察者集合属性
    private List<Observe> observeList;

    //温度
    private int temper;

    //湿度
    private int hindym;

    //压强
    private int press;


    public WeatherData() {
        this.observeList = new ArrayList<>();
    }


    public void setWeatherProper(int temper,int hindym,int press){
        this.temper=temper;
        this.hindym=hindym;
        this.press=press;
        notifyObser();
    }


    @Override
    public void registerObser(Observe observe) {
        observeList.add(observe);
    }

    @Override
    public void removeObser(Observe observe) {
        int indexOf = observeList.indexOf(observe);
        if(indexOf>=0){
            observeList.remove(indexOf);
        }

    }

    @Override
    public void notifyObser() {
        for (Observe observe : observeList) {
         observe.update(temper,hindym,press);
        }
    }
}
